/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_INCLUDE_HARDWARE_BEAR_PI_H
#define ANDROID_INCLUDE_HARDWARE_BEAR_PI_H

#include <hardware/hardware.h>
#include <hardware/hw_auth_token.h>

#define BEAR_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
#define BEAR_HARDWARE_MODULE_ID "bearpi" //需要与库名称相同 bearpi.default.so,否则找不到hal

typedef enum bear_msg_type {
    BEAR_ERROR = -1,
    BEAR_ACQUIRED = 1,
    BEAR_ACCELEANDGYRO,
    BEAR_ANGLE_VALUE,
    BEAR_TEMP,
} bear_msg_type_t;


/*
 * Bear acquisition info is meant as feedback for the current operation.  Anything but
 * BEAR_ACQUIRED_GOOD will be shown to the user as feedback on how to take action on the
 * current operation. For example, BEAR_ACQUIRED_IMAGER_DIRTY can be used to tell the user
 * to clean the sensor.  If this will cause the current operation to fail,
 * In general, these messages will result in a "Try again" message.
 */
typedef enum bear_acquired_info {
    BEAR_ACQUIRED_GOOD = 0,
    BEAR_ACQUIRED_PARTIAL = 1, /* sensor needs more data, i.e. longer swipe. */
    BEAR_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
} bear_acquired_info_t;


typedef struct bear_acquired {
    bear_acquired_info_t acquired_info; /* information about the image */
} bear_acquired_t;


typedef struct bear_msg {
    bear_msg_type_t type;
    union {
        bear_acquired_t acquired;
    } data;
    float acceles[3];
    float gyros[3];
    float pitch;
    float roll;
    float yaw;
    float cpu_temp;
} bear_msg_t;

/* Callback function type */
typedef void (*bear_notify_t)(const bear_msg_t *msg);

/* Synchronous operation */
typedef struct bear_device {
    /**
     * Common methods of the fingerprint device. This *must* be the first member
     * of fingerprint_device as users of this structure will cast a hw_device_t
     * to fingerprint_device pointer in contexts where it's known
     * the hw_device_t references a fingerprint_device.
     */
    struct hw_device_t common;

    /*
     * Client provided callback function to receive notifications.
     * Do not set by hand, use the function above instead.
     */
    bear_notify_t notify;

    /*
     * Set notification callback:
     * Registers a user function that would receive notifications from the HAL
     * The call will block if the HAL state machine is in busy state until HAL
     * leaves the busy state.
     *
     * Function return: 0 if callback function is successfuly registered
     *                  or a negative number in case of error, generally from the errno.h set.
     */
    int (*set_notify)(struct bear_device *dev, bear_notify_t notify);

    uint64_t (*test)(struct bear_device *dev);
    uint64_t (*start_get_angle)(void);
    uint64_t (*stop_get_angle)(void);
    int (*set_val)(struct bear_device *dev, int val);
    int (*get_val)(struct bear_device *dev, int *val);

    void (*get_cpu_temp)(struct bear_device *dev, float *temp);

    int fd;
} bear_device_t;

typedef struct bear_module {
    /**
     * Common methods of the bear module. This *must* be the first member
     * of bear_module as users of this structure will cast a hw_module_t
     * to bear_module pointer in contexts where it's known
     * the hw_module_t references a bear_module.
     */
    struct hw_module_t common;
} bear_module_t;

#endif  /* ANDROID_INCLUDE_HARDWARE_BEAR_PI_H */







